/*******************************************************************************
Code for Table 7: mean reversion in mu3
Provides empirical estimates of mean reversion
*******************************************************************************/

/*******************************************************************************
1. Using GOS series
*******************************************************************************/

/*
Process data from GOS
Spreadsheet can be downloaded from Fatih Guvenen's website
Ordering:
1. Year (t)
2. Std 1year
3. Std 5year
4. Skewness 1year
5. Skewness 5year
Data is for t-k to t
*/

import excel "gos-jpe2014-data.xlsx", sheet("Figure 4") cellrange(A5:E37) clear
rename A year
rename B std_1y
rename C std_5y
rename D skew_1y
rename E skew_5y

gen mu3_1y = skew_1y*(std_1y^3)
gen mu3_5y = skew_5y*(std_5y^3)

keep year mu3_1y mu3_5y

tsset year

// hp filter
tsfilter hp mu3_1y_hp = mu3_1y, smooth(100)
tsfilter hp mu3_5y_hp = mu3_5y, smooth(100)

// results: raw GOS series
corr mu3_1y_hp F.mu3_1y_hp
local corr_GOS_raw_nis2 = `r(rho)'
corr mu3_1y_hp F5.mu3_5y_hp
local corr_GOS_raw_nis6 = `r(rho)'

// proxies
gen mu3_1y_proxy = mu3_1y_hp
gen mu3_2y_proxy = mu3_1y_proxy + L.mu3_1y_hp
gen mu3_3y_proxy = mu3_2y_proxy + L2.mu3_1y_hp
gen mu3_4y_proxy = mu3_3y_proxy + L3.mu3_1y_hp
gen mu3_5y_proxy = mu3_4y_proxy + L4.mu3_1y_hp

// check correlations between raw GOS series and proxy
corr mu3_5y_proxy mu3_5y_hp
local check_corr_GOS_proxy_5y = `r(rho)'

// results: GOS series proxy
corr mu3_1y_proxy F.mu3_1y_proxy
local corr_GOS_proxy_nis2 = `r(rho)'

corr mu3_1y_proxy F2.mu3_2y_proxy
local corr_GOS_proxy_nis3 = `r(rho)'

corr mu3_1y_proxy F3.mu3_3y_proxy
local corr_GOS_proxy_nis4 = `r(rho)'

corr mu3_1y_proxy F4.mu3_4y_proxy
local corr_GOS_proxy_nis5 = `r(rho)'

corr mu3_1y_proxy F5.mu3_5y_proxy
local corr_GOS_proxy_nis6 = `r(rho)'

/*******************************************************************************
2. using uneployment changes
*******************************************************************************/

freduse UNRATE, clear
gen datem = mofd(daten)
format datem %tm

tsset datem

keep if datem>=ym(1964,1) & datem<=ym(2016,12)

tsfilter hp U = UNRATE, smooth(14400)

gen mu3_1y_proxy_unrate = U - L12.U
gen mu3_2y_proxy_unrate = U - L24.U
gen mu3_3y_proxy_unrate = U - L36.U
gen mu3_4y_proxy_unrate = U - L48.U
gen mu3_5y_proxy_unrate = U - L60.U

// results: unemployment change proxy
corr mu3_1y_proxy_unrate F12.mu3_1y_proxy_unrate
local corr_unrate_proxy_nis2 = `r(rho)'

corr mu3_1y_proxy_unrate F24.mu3_2y_proxy_unrate
local corr_unrate_proxy_nis3 = `r(rho)'

corr mu3_1y_proxy_unrate F36.mu3_3y_proxy_unrate
local corr_unrate_proxy_nis4 = `r(rho)'

corr mu3_1y_proxy_unrate F48.mu3_4y_proxy_unrate
local corr_unrate_proxy_nis5 = `r(rho)'

corr mu3_1y_proxy_unrate F60.mu3_5y_proxy_unrate
local corr_unrate_proxy_nis6 = `r(rho)'

/*******************************************************************************
3. report results
*******************************************************************************/

di "Using GOS data:"
di "n=2: "`corr_GOS_raw_nis2'
di "n=6: "`corr_GOS_raw_nis6'

di "Check correlation: GOS vs proxy for 5 years"
di `check_corr_GOS_proxy_5y'

di "Using GOS proxy:"
di "n=2: "`corr_GOS_proxy_nis2'
di "n=3: "`corr_GOS_proxy_nis3'
di "n=4: "`corr_GOS_proxy_nis4'
di "n=5: "`corr_GOS_proxy_nis5'
di "n=6: "`corr_GOS_proxy_nis6'

di "Using unemployment change:"
di "n=2: "`corr_unrate_proxy_nis2'
di "n=3: "`corr_unrate_proxy_nis3'
di "n=4: "`corr_unrate_proxy_nis4'
di "n=5: "`corr_unrate_proxy_nis5'
di "n=6: "`corr_unrate_proxy_nis6'